﻿#ifndef PRODUCTVIEW_H
#define PRODUCTVIEW_H
#include"XQOperateView.h"
#include"ProductModel.h"
class QCompleter;
//商品视图
class ProductView:public XQOperateView
{
	Q_OBJECT
public:
	ProductView(QWidget* parent = nullptr);
	~ProductView();
	enum class Type;
public:
	void setReadOnly(bool readOnly)override;
	void setReadOnly(int type, bool readOnly)override;
	template<typename T = Type>
	void setReadOnly(T type, bool readOnly);
public:
	ProductModel productModel()const;
	quint64 product_id()const;
	QString name()const;
	QString type()const;
	double price()const;
	quint64 number()const;
	double totalPrice()const;
	QDateTime mtime()const;
	QDateTime ctime()const;
public:
	void setProductModel(const ProductModel& model);
	void setProduct_id(quint64 product_id);
	void setName(const QString& name);
	void setType(const QString& type);
	void setPrice(double price, char format = 'g', int precision = 6);
	void setNumber(quint64 number);
	void setNumberRange(int minimum, int maximum);
	void setTotalPrice(double totalPrice, char format = 'g', int precision = 6);
	void setMTime(const QDateTime& time);
	void setCTime(const QDateTime& time);

	void setNameCompleter(const QStringList& list);
	void setNameItems(const QStringList& list);
	void setTypeCompleter(const QStringList& list);
	void setTypeItems(const QStringList& list);
signals://信号
	void requestTypeSignals(const QString& name);
public:
	//初始化
	void init()override;
	void okButtonSlots()override;
protected://初始化和ui界面
	//初始化UI
	virtual void init_ui();
	QWidget* init_id();
	QWidget* init_name();
	QWidget* init_type();
	QWidget* init_price();
	QWidget* init_number();
	QWidget* init_totalPrice();
	//修改时间初始化
	virtual QWidget* init_mtimeEdit();
	//创建时间初始化
	virtual QWidget* init_ctimeEdit();
protected:
	QLineEdit* m_idEdit = nullptr;
	QComboBox* m_nameEdit = nullptr;
	QComboBox* m_typeEdit = nullptr;
	QLineEdit* m_priceEdit = nullptr;
	QSpinBox* m_numberEdit = nullptr;
	QLineEdit* m_totalPriceEdit = nullptr;
	QDateTimeEdit* m_mtimeEdit = nullptr;//修改时间编辑框
	QDateTimeEdit* m_ctimeEdit = nullptr;//创建时间编辑框
};
enum class ProductView::Type
{
	OkButtonType,
	CloseButtonType,
	IdType,
	NameType,
	TypeType,
	PriceType,
	NumberType,
	TotalPriceType,
	MtimeType,
	CtimeType,
};
template<typename T>
inline void ProductView::setReadOnly(T type, bool readOnly)
{
	setReadOnly((int)type,readOnly);
}

#endif

